<?php
/**
* ShopEx licence
*
* @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
* @license  http://ecos.shopex.cn/ ShopEx License
 */

class b2c_ctl_site_zhifuchange extends site_controller{
	function __construct($app){
        parent::__construct($app);
    }
    public function index($flag){
        $this->page('site/zhifuchange/0.html');
    }
    public function change(){
    	$payment_ids = $_POST['payment_id'];
    	$payment_ids = explode(',', $payment_ids);
    	foreach ($payment_ids as $key => $payment_id) {
    		$objbills = app::get('ectools')->model('order_bills');
			$objbills_items = $objbills->getList('*', array('bill_id'=>$payment_id));
    		$objOrders = app::get('b2c')->model('orders');
			$objpayment = app::get('ectools')->model('payments');
			$objOrders_items_model = app::get('b2c')->model('order_items');
			$res = $objpayment->getList('*', array('payment_id'=>$payment_id,'status'=>'succ'));
			$res = $res[0];
	        $objOrders_items = $objOrders_items_model->getList('*', array('order_id'=>$objbills_items['0']['rel_id']));
	        $sdf_order = $objOrders->dump($objbills_items['0']['rel_id'], '*');
			// file_put_contents('alipay.txt',serialize($sdf_order).date('H:i:s'),FILE_APPEND);
			//充值的时候不在这边进行进销存的收款同步 做个判断 2016年8月26日10:24:35 by shen
			if($sdf_order['member_id']){
				//支付宝收款同步到进销存
		        $params = array(
                    'member_id'=>$sdf_order['member_id'],
                    'money'=>$res['money'],
                    'mtime'=>date("Y-m-d", $res['t_payed']),
                    'id'=>$objbills_items['0']['rel_id'],
                    'paymethod'=>$res['pay_app_id'],//需手动修改支付方式
                    'payment_id'=>$res['payment_id'],
                );
                $obj_order_pay = kernel::single("b2c_order_pay");
                $rr=$obj_order_pay->_get_data_pay($params);

                //订单信息同步到进销存
                $obj_order_create = kernel::single("b2c_order_create");
                $r=$obj_order_create->_get_create_data2($sdf_order,$objOrders_items,$res['money']);
                if($r['rsp']===false) {
                    $order_c['order_id'] = $sdf_order['order_id'];
                    $order_c['order_tongbufail'] = 2;
                    $sdf_res = $objOrders->save($order_c);
                }
                var_export($r);
			}
    	}
    	echo "执行成功";
    }
}
